package cn.edu.lingnan.servlet.student;

import cn.edu.lingnan.pojo.Student;
import cn.edu.lingnan.service.StudentService;
import cn.edu.lingnan.service.StudentServiceMysqlImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/newStu")
public class NewStudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String sname=req.getParameter("sname");
        String password=req.getParameter("password");
        Student student=new Student(null,sname,password,"0","");
        System.out.println("要新增的学生信息："+student);
        StudentService service=new StudentServiceMysqlImpl();
        boolean flag=service.newStudent(student);
        if(flag){
            System.out.println("新增成功");
        }else{
            System.out.println("新增失败");
        }
        resp.sendRedirect("/student/queryAllStu");


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
